/**
 * 提供了prompt的封装
 * @author jinglf000
 */
import Vue from 'vue';
import userLogin from './userLogin';


const ConfirmConstructor = Vue.extend(userLogin);
let instance;

const initInstance = () => {
  instance = new ConfirmConstructor({
    el: document.createElement('div')
  });
};

/**
 * $userLogin 方法的封装
 * @param {Object} options 按钮文案 {confirmButtonText, cancelButtonText}
 * @return {Promise} 返回Promise
 * 注意：点击取消按钮的时候会返回，拒绝的Promise
 */
const $userLogin = function confirmFn(
) {
  return new Promise((resolve) => {
    if (!instance) {
      initInstance();
    }
    // 按钮
    instance.$on('login', event => {
      resolve(event);
    });
    document.body.appendChild(instance.$el);
    Vue.nextTick(() => {
      instance.visible = true;
    });
  });
};

export default $userLogin;
